home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / dflt18.arj / APPLICAT.C next >
Text File  |  1994-03-01  |  22KB  |  740 lines

  1. /* ------------- applicat.c ------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. static int ScreenHeight;
  6. static BOOL DisplayModified = FALSE;
  7. WINDOW ApplicationWindow;
  8.  
  9. extern DBOX Display;
  10. extern DBOX Windows;
  11.  
  12. #ifdef INCLUDE_LOGGING
  13. extern DBOX Log;
  14. #endif
  15.  
  16. #ifdef INCLUDE_SHELLDOS
  17. static void ShellDOS(WINDOW);
  18. #endif
  19. static void CreateMenu(WINDOW);
  20. static void CreateStatusBar(WINDOW);
  21. static void SelectColors(WINDOW);
  22. static void SetScreenHeight(int);
  23. static void SelectLines(WINDOW);
  24.  
  25. #ifdef INCLUDE_WINDOWOPTIONS
  26. static void SelectTexture(void);
  27. static void SelectBorder(WINDOW);
  28. static void SelectTitle(WINDOW);
  29. static void SelectStatusBar(WINDOW);
  30. #endif
  31.  
  32. static WINDOW oldFocus;
  33. #ifdef INCLUDE_MULTI_WINDOWS
  34. static void CloseAll(WINDOW, int);
  35. static void MoreWindows(WINDOW);
  36. static void ChooseWindow(WINDOW, int);
  37. static int WindowSel;
  38. static char *Menus[9] = {
  39.     "~1.                      ",
  40.     "~2.                      ",
  41.     "~3.                      ",
  42.     "~4.                      ",
  43.     "~5.                      ",
  44.     "~6.                      ",
  45.     "~7.                      ",
  46.     "~8.                      ",
  47.     "~9.                      "
  48. };
  49. #endif
  50.  
  51. static char Cwd[65];
  52.  
  53. /* --------------- CREATE_WINDOW Message -------------- */
  54. static int CreateWindowMsg(WINDOW wnd)
  55. {
  56.     int rtn;
  57.     ApplicationWindow = wnd;
  58.     ScreenHeight = SCREENHEIGHT;
  59.     getcwd(Cwd, 64);
  60.     if (!DisplayModified)    {
  61.            int i;
  62.            CTLWINDOW *ct, *ct1;
  63.            ct = FindCommand(&Display, ID_SNOWY, CHECKBOX);
  64.         if (!isVGA())    {
  65.             /* ---- modify Display Dialog Box for EGA, CGA ---- */
  66.             if (isEGA())
  67.                 ct1 = FindCommand(&Display,ID_50LINES,RADIOBUTTON);
  68.             else    {
  69.                 CTLWINDOW *ct2;
  70.                 ct2 = FindCommand(&Display,ID_COLOR,RADIOBUTTON)-1;
  71.                 if (ct2)    {
  72.                     ct2->dwnd.w++;
  73.                     for (i = 0; i < 7; i++)
  74.                         (ct2+i)->dwnd.x += 8;
  75.                 }
  76.                 ct1 = FindCommand(&Display,ID_25LINES,RADIOBUTTON)-1;
  77.             }
  78.             if (ct && ct1)
  79.                 for (i = 0; i < 6; i++)
  80.                     *ct1++ = *ct++;
  81.         }
  82.         if (isVGA() || isEGA())    {
  83.             /* ------ eliminate the snowy check box ----- */
  84.                ct = FindCommand(&Display, ID_SNOWY, CHECKBOX);
  85.             if (ct != NULL)
  86.                 for (i = 0; i < 4; i++)
  87.                     *(ct+i) = *(ct+2+i);
  88.         }
  89.         DisplayModified = TRUE;
  90.     }
  91. #ifdef INCLUDE_WINDOWOPTIONS
  92.     if (cfg.Border)
  93.         SetCheckBox(&Display, ID_BORDER);
  94.     if (cfg.Title)
  95.         SetCheckBox(&Display, ID_TITLE);
  96.     if (cfg.StatusBar)
  97.         SetCheckBox(&Display, ID_STATUSBAR);
  98.     if (cfg.Texture)
  99.         SetCheckBox(&Display, ID_TEXTURE);
  100. #endif
  101.     if (cfg.mono == 1)
  102.         PushRadioButton(&Display, ID_MONO);
  103.     else if (cfg.mono == 2)
  104.         PushRadioButton(&Display, ID_REVERSE);
  105.     else
  106.         PushRadioButton(&Display, ID_COLOR);
  107.     if (cfg.ScreenLines == 25)
  108.         PushRadioButton(&Display, ID_25LINES);
  109.     else if (cfg.ScreenLines == 43)
  110.         PushRadioButton(&Display, ID_43LINES);
  111.     else if (cfg.ScreenLines == 50)
  112.         PushRadioButton(&Display, ID_50LINES);
  113.     if (cfg.snowy)
  114.         SetCheckBox(&Display, ID_SNOWY);
  115.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  116.         SetScreenHeight(cfg.ScreenLines);
  117.         if (WindowHeight(wnd) == ScreenHeight ||
  118.                 SCREENHEIGHT-1 < GetBottom(wnd))    {
  119.             WindowHeight(wnd) = SCREENHEIGHT-1;
  120.             GetBottom(wnd) = GetTop(wnd)+WindowHeight(wnd);
  121.             wnd->RestoredRC = WindowRect(wnd);
  122.         }
  123.     }
  124.     SelectColors(wnd);
  125. #ifdef INCLUDE_WINDOWOPTIONS
  126.     SelectBorder(wnd);
  127.     SelectTitle(wnd);
  128.     SelectStatusBar(wnd);
  129. #endif
  130.     rtn = BaseWndProc(APPLICATION, wnd, CREATE_WINDOW, 0, 0);
  131.     if (wnd->extension != NULL)
  132.         CreateMenu(wnd);
  133.     CreateStatusBar(wnd);
  134.     SendMessage(NULL, SHOW_MOUSE, 0, 0);
  135.     return rtn;
  136. }
  137.  
  138. /* --------- ADDSTATUS Message ---------- */
  139. static void AddStatusMsg(WINDOW wnd, PARAM p1)
  140. {
  141.     if (wnd->StatusBar != NULL)    {
  142.         if (p1 && *(char *)p1)
  143.             SendMessage(wnd->StatusBar, SETTEXT, p1, 0);
  144.         else 
  145.             SendMessage(wnd->StatusBar, CLEARTEXT, 0, 0);
  146.         SendMessage(wnd->StatusBar, PAINT, 0, 0);
  147.     }
  148. }
  149.  
  150. /* -------- SETFOCUS Message -------- */
  151. static void SetFocusMsg(WINDOW wnd, BOOL p1)
  152. {
  153.     if (p1)
  154.         SendMessage(inFocus, SETFOCUS, FALSE, 0);
  155.     inFocus = p1 ? wnd : NULL;
  156.     if (isVisible(wnd))
  157.         SendMessage(wnd, BORDER, 0, 0);
  158.     else 
  159.         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  160. }
  161.  
  162. /* ------- SIZE Message -------- */
  163. static void SizeMsg(WINDOW wnd, PARAM p1, PARAM p2)
  164. {
  165.     BOOL WasVisible;
  166.     WasVisible = isVisible(wnd);
  167.     if (WasVisible)
  168.         SendMessage(wnd, HIDE_WINDOW, 0, 0);
  169.     if (p1-GetLeft(wnd) < 30)
  170.         p1 = GetLeft(wnd) + 30;
  171.     BaseWndProc(APPLICATION, wnd, SIZE, p1, p2);
  172.     CreateMenu(wnd);
  173.     CreateStatusBar(wnd);
  174.     if (WasVisible)
  175.         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  176. }
  177.  
  178. /* ----------- KEYBOARD Message ------------ */
  179. static int KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
  180. {
  181.     if (WindowMoving || WindowSizing || (int) p1 == F1)
  182.         return BaseWndProc(APPLICATION, wnd, KEYBOARD, p1, p2);
  183.     switch ((int) p1)    {
  184.         case ALT_F4:
  185.             if (TestAttribute(wnd, CONTROLBOX))
  186.                 PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  187.             return TRUE;
  188. #ifdef INCLUDE_MULTI_WINDOWS
  189.         case ALT_F6:
  190.             SetNextFocus();
  191.             return TRUE;
  192. #endif
  193.         case ALT_HYPHEN:
  194.             if (TestAttribute(wnd, CONTROLBOX))
  195.                 BuildSystemMenu(wnd);
  196.             return TRUE;
  197.         default:
  198.             break;
  199.     }
  200.     PostMessage(wnd->MenuBarWnd, KEYBOARD, p1, p2);
  201.     return TRUE;
  202. }
  203.  
  204. /* --------- SHIFT_CHANGED Message -------- */
  205. static void ShiftChangedMsg(WINDOW wnd, PARAM p1)
  206. {
  207.     extern BOOL AltDown;
  208.     if ((int)p1 & ALTKEY)
  209.         AltDown = TRUE;
  210.     else if (AltDown)    {
  211.         AltDown = FALSE;
  212.         if (wnd->MenuBarWnd != inFocus)
  213.             SendMessage(NULL, HIDE_CURSOR, 0, 0);
  214.         SendMessage(wnd->MenuBarWnd, KEYBOARD, F10, 0);
  215.     }
  216. }
  217.  
  218. /* -------- COMMAND Message ------- */
  219. static void CommandMsg(WINDOW wnd, PARAM p1, PARAM p2)
  220. {
  221.     switch ((int)p1)    {
  222.         case ID_HELP:
  223.             DisplayHelp(wnd, DFlatApplication);
  224.             break;
  225.         case ID_HELPHELP:
  226.             DisplayHelp(wnd, "HelpHelp");
  227.             break;
  228.         case ID_EXTHELP:
  229.             DisplayHelp(wnd, "ExtHelp");
  230.             break;
  231.         case ID_KEYSHELP:
  232.             DisplayHelp(wnd, "KeysHelp");
  233.             break;
  234.         case ID_HELPINDEX:
  235.             DisplayHelp(wnd, "HelpIndex");
  236.             break;
  237. #ifdef INCLUDE_LOGGING
  238.         case ID_LOG:
  239.             MessageLog(wnd);
  240.             break;
  241. #endif
  242. #ifdef INCLUDE_SHELLDOS
  243.         case ID_DOS:
  244.             ShellDOS(wnd);
  245.             break;
  246. #endif
  247.         case ID_EXIT:
  248.         case ID_SYSCLOSE:
  249.             PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  250.             break;
  251.         case ID_DISPLAY:
  252.             if (DialogBox(wnd, &Display, TRUE, NULL))    {
  253.                 if (inFocus == wnd->MenuBarWnd || inFocus == wnd->StatusBar)
  254.                     oldFocus = ApplicationWindow;
  255.                 else 
  256.                     oldFocus = inFocus;
  257.                 SendMessage(wnd, HIDE_WINDOW, 0, 0);
  258.                 SelectColors(wnd);
  259.                 SelectLines(wnd);
  260. #ifdef INCLUDE_WINDOWOPTIONS
  261.                 SelectBorder(wnd);
  262.                 SelectTitle(wnd);
  263.                 SelectStatusBar(wnd);
  264.                 SelectTexture();
  265. #endif
  266.                 CreateMenu(wnd);
  267.                 CreateStatusBar(wnd);
  268.                 SendMessage(wnd, SHOW_WINDOW, 0, 0);
  269.                 SendMessage(oldFocus, SETFOCUS, TRUE, 0);
  270.             }
  271.             break;
  272.         case ID_SAVEOPTIONS:
  273.             SaveConfig();
  274.             break;
  275. #ifdef INCLUDE_MULTI_WINDOWS
  276.         case ID_WINDOW:
  277.             ChooseWindow(wnd, (int)p2-2);
  278.             break;
  279.         case ID_CLOSEALL:
  280.             CloseAll(wnd, FALSE);
  281.             break;
  282.         case ID_MOREWINDOWS:
  283.             MoreWindows(wnd);
  284.             break;
  285. #endif
  286. #ifdef INCLUDE_RESTORE
  287.         case ID_SYSRESTORE:
  288. #endif
  289.         case ID_SYSMOVE:
  290.         case ID_SYSSIZE:
  291. #ifdef INCLUDE_MINIMIZE
  292.         case ID_SYSMINIMIZE:
  293. #endif
  294. #ifdef INCLUDE_MAXIMIZE
  295.         case ID_SYSMAXIMIZE:
  296. #endif
  297.             BaseWndProc(APPLICATION, wnd, COMMAND, p1, p2);
  298.             break;
  299.         default:
  300.             if (inFocus != wnd->MenuBarWnd && inFocus != wnd)
  301.                 PostMessage(inFocus, COMMAND, p1, p2);
  302.             break;
  303.     }
  304. }
  305.  
  306. /* --------- CLOSE_WINDOW Message -------- */
  307. static int CloseWindowMsg(WINDOW wnd)
  308. {
  309.     int rtn;
  310. #ifdef INCLUDE_MULTI_WINDOWS
  311.     CloseAll(wnd, TRUE);
  312.     WindowSel = 0;
  313. #endif
  314.     PostMessage(NULL, STOP, 0, 0);
  315.     rtn = BaseWndProc(APPLICATION, wnd, CLOSE_WINDOW, 0, 0);
  316.     if (ScreenHeight != SCREENHEIGHT)
  317.         SetScreenHeight(ScreenHeight);
  318.     UnLoadHelpFile();
  319.     DisplayModified = FALSE;
  320.     ApplicationWindow = NULL;
  321.     setdisk(toupper(*Cwd) - 'A');
  322.     chdir(Cwd+2);
  323.     return rtn;
  324. }
  325.  
  326. /* --- APPLICATION Window Class window processing module --- */
  327. int ApplicationProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  328. {
  329.     switch (msg)    {
  330.         case CREATE_WINDOW:
  331.             return CreateWindowMsg(wnd);
  332.         case HIDE_WINDOW:
  333.             if (wnd == inFocus)
  334.                 inFocus = NULL;
  335.             break;
  336.         case ADDSTATUS:
  337.             AddStatusMsg(wnd, p1);
  338.             return TRUE;
  339.         case SETFOCUS:
  340.             if ((int)p1 == (inFocus != wnd))    {
  341.                 SetFocusMsg(wnd, (BOOL) p1);
  342.                 return TRUE;
  343.             }
  344.             break;
  345.         case SIZE:
  346.             SizeMsg(wnd, p1, p2);
  347.             return TRUE;
  348. #ifdef INCLUDE_MINIMIZE
  349.         case MINIMIZE:
  350.             return TRUE;
  351. #endif
  352.         case KEYBOARD:
  353.             return KeyboardMsg(wnd, p1, p2);
  354.         case SHIFT_CHANGED:
  355.             ShiftChangedMsg(wnd, p1);
  356.             return TRUE;
  357.         case PAINT:
  358.             if (isVisible(wnd))    {
  359. #ifdef INCLUDE_WINDOWOPTIONS
  360.                 int cl = cfg.Texture ? APPLCHAR : ' ';
  361. #else
  362.                 int cl = APPLCHAR;
  363. #endif
  364.                 ClearWindow(wnd, (RECT *)p1, cl);
  365.             }
  366.             return TRUE;
  367.         case COMMAND:
  368.             CommandMsg(wnd, p1, p2);
  369.             return TRUE;
  370.         case CLOSE_WINDOW:
  371.             return CloseWindowMsg(wnd);
  372.         default:
  373.             break;
  374.     }
  375.     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  376. }
  377.  
  378. #ifdef INCLUDE_SHELLDOS
  379. static void SwitchCursor(void)
  380. {
  381.     SendMessage(NULL, SAVE_CURSOR, 0, 0);
  382.     SwapCursorStack();
  383.     SendMessage(NULL, RESTORE_CURSOR, 0, 0);
  384. }
  385.  
  386. /* ------- Shell out to DOS ---------- */
  387. static void ShellDOS(WINDOW wnd)
  388. {
  389.     oldFocus = inFocus;
  390.     SendMessage(wnd, HIDE_WINDOW, 0, 0);
  391.     SwitchCursor();
  392.     if (ScreenHeight != SCREENHEIGHT)
  393.         SetScreenHeight(ScreenHeight);
  394.     SendMessage(NULL, HIDE_MOUSE, 0, 0);
  395.     printf("To return to %s, execute the DOS exit command.",
  396.                     DFlatApplication);
  397.     fflush(stdout);
  398.     spawnl(P_WAIT, getenv("COMSPEC"), NULL);
  399.     if (SCREENHEIGHT != cfg.ScreenLines)
  400.         SetScreenHeight(cfg.ScreenLines);
  401.     SwitchCursor();
  402.     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  403.     SendMessage(oldFocus, SETFOCUS, TRUE, 0);
  404.     SendMessage(NULL, SHOW_MOUSE, 0, 0);
  405. }
  406. #endif
  407.  
  408. /* -------- Create the menu bar -------- */
  409. static void CreateMenu(WINDOW wnd)
  410. {
  411.     AddAttribute(wnd, HASMENUBAR);
  412.     if (wnd->MenuBarWnd != NULL)
  413.         SendMessage(wnd->MenuBarWnd, CLOSE_WINDOW, 0, 0);
  414.     wnd->MenuBarWnd = CreateWindow(MENUBAR,
  415.                         NULL,
  416.                         GetClientLeft(wnd),
  417.                         GetClientTop(wnd)-1,
  418.                         1,
  419.                         ClientWidth(wnd),
  420.                         NULL,
  421.                         wnd,
  422.                         NULL,
  423.                         0);
  424.     SendMessage(wnd->MenuBarWnd,BUILDMENU,
  425.         (PARAM)wnd->extension,0);
  426.     AddAttribute(wnd->MenuBarWnd, VISIBLE);
  427. }
  428.  
  429. /* ----------- Create the status bar ------------- */
  430. static void CreateStatusBar(WINDOW wnd)
  431. {
  432.     if (wnd->StatusBar != NULL)    {
  433.         SendMessage(wnd->StatusBar, CLOSE_WINDOW, 0, 0);
  434.         wnd->StatusBar = NULL;
  435.     }
  436.     if (TestAttribute(wnd, HASSTATUSBAR))    {
  437.         wnd->StatusBar = CreateWindow(STATUSBAR,
  438.                             NULL,
  439.                             GetClientLeft(wnd),
  440.                             GetBottom(wnd),
  441.                             1,
  442.                             ClientWidth(wnd),
  443.                             NULL,
  444.                             wnd,
  445.                             NULL,
  446.                             0);
  447.         AddAttribute(wnd->StatusBar, VISIBLE);
  448.     }
  449. }
  450.  
  451. #ifdef INCLUDE_MULTI_WINDOWS
  452. /* -------- return the name of a document window ------- */
  453. static char *WindowName(WINDOW wnd)
  454. {
  455.     if (GetTitle(wnd) == NULL)    {
  456.         if (GetClass(wnd) == DIALOG)
  457.             return ((DBOX *)(wnd->extension))->HelpName;
  458.         else 
  459.             return "Untitled";
  460.     }
  461.     else
  462.         return GetTitle(wnd);
  463. }
  464.  
  465. /* ----------- Prepare the Window menu ------------ */
  466. void PrepWindowMenu(void *w, struct Menu *mnu)
  467. {
  468.     WINDOW wnd = w;
  469.     struct PopDown *p0 = mnu->Selections;
  470.     struct PopDown *pd = mnu->Selections + 2;
  471.     struct PopDown *ca = mnu->Selections + 13;
  472.     int MenuNo = 0;
  473.     WINDOW cwnd;
  474.     mnu->Selection = 0;
  475.     oldFocus = NULL;
  476.     if (GetClass(wnd) != APPLICATION)    {
  477.         oldFocus = wnd;
  478.         /* ----- point to the APPLICATION window ----- */
  479.         if (ApplicationWindow == NULL)
  480.             return;
  481.         cwnd = FirstWindow(ApplicationWindow);
  482.         /* ----- get the first 9 document windows ----- */
  483.         while (cwnd != NULL && MenuNo < 9)    {
  484.             if (GetClass(cwnd) != MENUBAR &&
  485.                     GetClass(cwnd) != STATUSBAR) {
  486.                 /* --- add the document window to the menu --- */
  487.                 strncpy(Menus[MenuNo]+4, WindowName(cwnd), 20);
  488.                 pd->SelectionTitle = Menus[MenuNo];
  489.                 if (cwnd == oldFocus)    {
  490.                     /* -- mark the current document -- */
  491.                     pd->Attrib |= CHECKED;
  492.                     mnu->Selection = MenuNo+2;
  493.                 }
  494.                 else
  495.                     pd->Attrib &= ~CHECKED;
  496.                 pd++;
  497.                 MenuNo++;
  498.             }
  499.             cwnd = NextWindow(cwnd);
  500.         }
  501.     }
  502.     if (MenuNo)
  503.         p0->SelectionTitle = "~Close all";
  504.     else
  505.         p0->SelectionTitle = NULL;
  506.     if (MenuNo >= 9)    {
  507.         *pd++ = *ca;
  508.         if (mnu->Selection == 0)
  509.             mnu->Selection = 11;
  510.     }
  511.     pd->SelectionTitle = NULL;
  512. }
  513.  
  514. /* window processing module for the More Windows dialog box */
  515. static int WindowPrep(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  516. {
  517.     switch (msg)    {
  518.         case INITIATE_DIALOG:    {
  519.             WINDOW wnd1;
  520.             WINDOW cwnd = ControlWindow(&Windows,ID_WINDOWLIST);
  521.             int sel = 0;
  522.             if (cwnd == NULL)
  523.                 return FALSE;
  524.             wnd1 = FirstWindow(ApplicationWindow);
  525.             while (wnd1 != NULL)    {
  526.                 if (wnd1 != wnd && GetClass(wnd1) != MENUBAR &&
  527.                         GetClass(wnd1) != STATUSBAR)    {
  528.                     if (wnd1 == oldFocus)
  529.                         WindowSel = sel;
  530.                     SendMessage(cwnd, ADDTEXT,
  531.                         (PARAM) WindowName(wnd1), 0);
  532.                     sel++;
  533.                 }
  534.                 wnd1 = NextWindow(wnd1);
  535.             }
  536.             SendMessage(cwnd, LB_SETSELECTION, WindowSel, 0);
  537.             AddAttribute(cwnd, VSCROLLBAR);
  538.             PostMessage(cwnd, SHOW_WINDOW, 0, 0);
  539.             break;
  540.         }
  541.         case COMMAND:
  542.             switch ((int) p1)    {
  543.                 case ID_OK:
  544.                     if ((int)p2 == 0)
  545.                         WindowSel = SendMessage(
  546.                                     ControlWindow(&Windows,
  547.                                     ID_WINDOWLIST),
  548.                                     LB_CURRENTSELECTION, 0, 0);
  549.                     break;
  550.                 case ID_WINDOWLIST:
  551.                     if ((int) p2 == LB_CHOOSE)
  552.                         SendMessage(wnd, COMMAND, ID_OK, 0);
  553.                     break;
  554.                 default:
  555.                     break;
  556.             }
  557.             break;
  558.         default:
  559.             break;
  560.     }
  561.     return DefaultWndProc(wnd, msg, p1, p2);
  562. }
  563.  
  564. /* ---- the More Windows command on the Window menu ---- */
  565. static void MoreWindows(WINDOW wnd)
  566. {
  567.     if (DialogBox(wnd, &Windows, TRUE, WindowPrep))
  568.         ChooseWindow(wnd, WindowSel);
  569. }
  570.  
  571. /* ----- user chose a window from the Window menu
  572.         or the More Window dialog box ----- */
  573. static void ChooseWindow(WINDOW wnd, int WindowNo)
  574. {
  575.     WINDOW cwnd = FirstWindow(wnd);
  576.     while (cwnd != NULL)    {
  577.         if (GetClass(cwnd) != MENUBAR &&
  578.                 GetClass(cwnd) != STATUSBAR)
  579.             if (WindowNo-- == 0)
  580.                 break;
  581.         cwnd = NextWindow(cwnd);
  582.     }
  583.     if (cwnd != NULL)    {
  584.         SendMessage(cwnd, SETFOCUS, TRUE, 0);
  585.         if (cwnd->condition == ISMINIMIZED)
  586.             SendMessage(cwnd, RESTORE, 0, 0);
  587.     }
  588. }
  589.  
  590. /* ----- Close all document windows ----- */
  591. static void CloseAll(WINDOW wnd, int closing)
  592. {
  593.     WINDOW wnd1, wnd2;
  594.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  595.     wnd1 = LastWindow(wnd);
  596.     while (wnd1 != NULL)    {
  597.         wnd2 = PrevWindow(wnd1);
  598.         if (GetClass(wnd1) != MENUBAR && GetClass(wnd1) != STATUSBAR)    {
  599.             ClearVisible(wnd1);
  600.             SendMessage(wnd1, CLOSE_WINDOW, 0, 0);
  601.         }
  602.         wnd1 = wnd2;
  603.     }
  604.     if (!closing)
  605.         SendMessage(wnd, PAINT, 0, 0);
  606. }
  607.  
  608. #endif    /* #ifdef INCLUDE_MULTI_WINDOWS */
  609.  
  610. static void DoWindowColors(WINDOW wnd)
  611. {
  612.     WINDOW cwnd;
  613.     InitWindowColors(wnd);
  614.     cwnd = FirstWindow(wnd);
  615.     while (cwnd != NULL)    {
  616.         DoWindowColors(cwnd);
  617.         if (GetClass(cwnd) == TEXT && GetText(cwnd) != NULL)
  618.             SendMessage(cwnd, CLEARTEXT, 0, 0);
  619.         cwnd = NextWindow(cwnd);
  620.     }
  621. }
  622.  
  623. /* ----- set up colors for the application window ------ */
  624. static void SelectColors(WINDOW wnd)
  625. {
  626.     if (RadioButtonSetting(&Display, ID_MONO))
  627.         cfg.mono = 1;
  628.     else if (RadioButtonSetting(&Display, ID_REVERSE))
  629.         cfg.mono = 2;
  630.     else
  631.         cfg.mono = 0;
  632.     cfg.snowy = CheckBoxSetting(&Display, ID_SNOWY);
  633.     get_videomode();
  634.     if ((ismono() || video_mode == 2) && cfg.mono == 0)
  635.         cfg.mono = 1;
  636.  
  637.     if (cfg.mono == 1)
  638.         memcpy(cfg.clr, bw, sizeof bw);
  639.     else if (cfg.mono == 2)
  640.         memcpy(cfg.clr, reverse, sizeof reverse);
  641.     else
  642.         memcpy(cfg.clr, color, sizeof color);
  643.     DoWindowColors(wnd);
  644. }
  645.  
  646. /* ---- select screen lines ---- */
  647. static void SelectLines(WINDOW wnd)
  648. {
  649.     cfg.ScreenLines = 25;
  650.     if (isEGA() || isVGA())    {
  651.         if (RadioButtonSetting(&Display, ID_43LINES))
  652.             cfg.ScreenLines = 43;
  653.         else if (RadioButtonSetting(&Display, ID_50LINES))
  654.             cfg.ScreenLines = 50;
  655.     }
  656.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  657.         SetScreenHeight(cfg.ScreenLines);
  658.         /* ---- re-maximize ---- */
  659.         if (wnd->condition == ISMAXIMIZED)    {
  660.             SendMessage(wnd, SIZE, (PARAM) GetRight(wnd),
  661.                 SCREENHEIGHT-1);
  662.             return;
  663.         }
  664.         /* --- adjust if current size does not fit --- */
  665.         if (WindowHeight(wnd) > SCREENHEIGHT)
  666.             SendMessage(wnd, SIZE, (PARAM) GetRight(wnd),
  667.                 (PARAM) GetTop(wnd)+SCREENHEIGHT-1);
  668.         /* --- if window is off-screen, move it on-screen --- */
  669.         if (GetTop(wnd) >= SCREENHEIGHT-1)
  670.             SendMessage(wnd, MOVE, (PARAM) GetLeft(wnd),
  671.                 (PARAM) SCREENHEIGHT-WindowHeight(wnd));
  672.     }
  673. }
  674.  
  675. /* ---- set the screen height in the video hardware ---- */
  676. static void SetScreenHeight(int height)
  677. {
  678.     if (isEGA() || isVGA())    {
  679.         SendMessage(NULL, SAVE_CURSOR, 0, 0);
  680.         switch (height)    {
  681.             case 25:
  682.                 Set25();
  683.                 break;
  684.             case 43:
  685.                 Set43();
  686.                 break;
  687.             case 50:
  688.                 Set50();
  689.                 break;
  690.             default:
  691.                 break;
  692.         }
  693.         SendMessage(NULL, RESTORE_CURSOR, 0, 0);
  694.         SendMessage(NULL, RESET_MOUSE, 0, 0);
  695.         SendMessage(NULL, SHOW_MOUSE, 0, 0);
  696.     }
  697. }
  698.  
  699. #ifdef INCLUDE_WINDOWOPTIONS
  700.  
  701. /* ----- select the screen texture ----- */
  702. static void SelectTexture(void)
  703. {
  704.     cfg.Texture = CheckBoxSetting(&Display, ID_TEXTURE);
  705. }
  706.  
  707. /* -- select whether the application screen has a border -- */
  708. static void SelectBorder(WINDOW wnd)
  709. {
  710.     cfg.Border = CheckBoxSetting(&Display, ID_BORDER);
  711.     if (cfg.Border)
  712.         AddAttribute(wnd, HASBORDER);
  713.     else
  714.         ClearAttribute(wnd, HASBORDER);
  715. }
  716.  
  717. /* select whether the application screen has a status bar */
  718. static void SelectStatusBar(WINDOW wnd)
  719. {
  720.     cfg.StatusBar = CheckBoxSetting(&Display, ID_STATUSBAR);
  721.     if (cfg.StatusBar)
  722.         AddAttribute(wnd, HASSTATUSBAR);
  723.     else
  724.         ClearAttribute(wnd, HASSTATUSBAR);
  725. }
  726.  
  727. /* select whether the application screen has a title bar */
  728. static void SelectTitle(WINDOW wnd)
  729. {
  730.     cfg.Title = CheckBoxSetting(&Display, ID_TITLE);
  731.     if (cfg.Title)
  732.         AddAttribute(wnd, HASTITLEBAR);
  733.     else
  734.         ClearAttribute(wnd, HASTITLEBAR);
  735. }
  736.  
  737. #endif
  738.  
  739. 
  740.